import Vue from "vue";
import VueRouter from "vue-router";


//组件
const Layout = ()=> import('@/views/layout/index.vue');
const Index =()=> import('@/views/index/index.vue');
const Login = ()=> import('@/views/login/index.vue');
const HomeIndex =()=>import('@/views/home/index.vue')
const MyProject =()=>import('@/views/MyProject/index.vue')
const ST =()=>import('@/views/ST/index.vue')
const SP =()=>import('@/views/SP/index.vue')
const FIAS =()=>import('@/views/FIAS/index.vue')
const InformationEntropy =()=>import('@/views/InformationEntropy/index.vue')
const UserInfo =()=>import('@/views/UserInfo/index.vue')
const Register =()=>import('@/views/register/index.vue')

Vue.use(VueRouter);

/**
 *	重写 router.prototype.push 避免同时跳转相同路径报错
 */
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
}

const routers=[
    {
        path: '/',
        name: 'layout',
        component: Layout,
        redirect:'/index',
        children:[
            {
                path:'index',
                name:'Index',
                component:Index
            },
            {
                path: 'login',
                name: 'Login',
                component: Login
            },
            {
                path: 'register',
                name: 'Register',
                component: Register
            }
        ]
    },
    {
        path: '/home/',
        name: 'Home',
        redirect: '/home/MyProject',
        component: HomeIndex,
        children:[
            {
                path: 'MyProject',
                name: 'MyProject',
                component: MyProject
            },
            {
                path: 'InformationEntropy',
                name: 'InformationEntropy',
                component: InformationEntropy
            },
            {
                path: 'ST',
                name: 'ST',
                component: ST
            },
            {
                path: 'SP',
                name: 'SP',
                component: SP
            },
            {
                path: 'FIAS',
                name: 'FIAS',
                component: FIAS
            },
            {
                path: 'UserInfo',
                name: 'UserInfo',
                component: UserInfo
            },
        ],
    },
]

export default routers
